﻿using System;
using System.Collections.Generic;

using CrudServices;
using CrudServices.EF;

namespace SimpleExample
{
    internal static class Program
    {
        private static void Main()
        {
            //This represents the server portion, where we create an ICrudService implementation that
            //can talk to the Northwind Entity Framework context
            var crudService = new CrudServiceEF<NorthwindContext>();

            //This represents the client portion. The CrudClient class requires a concrete implementation
            //of the ICrudService, so we can simply pass in crudService variable from above.
            var client = new CrudClient(crudService);

            SearchCriteria criteria = SearchCriteriaBuilder
                .From<Product>()
                .OrderBy(p => p.ProductName)
                .SelectAll();
            IEnumerable<Product> products = client.Search<Product>(criteria);
            foreach (Product product in products)
                Console.WriteLine("{0,-3} {1}", product.ProductID, product.ProductName);

            Console.WriteLine();
            Console.WriteLine("Press <Enter> to quit");
            Console.ReadLine();
        }
    }
}